/*
 * ChoiceNetPanel.java
 *
 * 
 */

package it.luigiarpino.alt2jsim.netpanel.nlevel;

import it.luigiarpino.alt2jsim.netpanel.flat.CirclePanel;
import it.luigiarpino.alt2jsim.netpanel.flat.NetPanel;
import it.luigiarpino.alt2jsim.network.N_Level_Network;
import javax.swing.*;
import java.awt.*;

/**
 *
 * @author  Luigi Lorenzo Arpino 534/559
 */
public class ChoiceNetPanel extends JPanel {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 1221964030954943224L;
	private JComboBox jComboBoxScegliRete;
    private JLabel jLabelScegliRete;
    private String[] nomiNodi;
    private JPanel jPanelSouthPanel;
    private NetPanel netPanel;
    private N_Level_Network net;
    private int level;
    
    /** Mostra nodi come reti di terzo livello*/
    public static final int SHOW_LEVEL_2=2;
    /** Mostra nodi come router */
    public static final int SHOW_LEVEL_3=3;
    
    /** Creates a new instance of ChoiceNetPanel
     se level=1 => lo zoom di una rete di primo livello
     se level=2 => zoom rete di terzo livello*/
    public ChoiceNetPanel(N_Level_Network net_,int level_) {
        super();
        try { 
            javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());     
    	} 
    	catch(Exception e) { }
        this.net =net_;
        this.level=level_;
        if (level== ChoiceNetPanel.SHOW_LEVEL_2){
            this.jComboBoxScegliRete=new JComboBox();
            this.nomiNodi=net.getLevel_1_Name();
            String[] model=new String[this.nomiNodi.length];
            for(int i=0;i<this.nomiNodi.length;i++){
                model[i]="  "+this.nomiNodi[i]+"  ";
            }
            this.jComboBoxScegliRete.setModel(new javax.swing.DefaultComboBoxModel(model));
            this.jComboBoxScegliRete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ComboActionPerformed(evt);
                }
            });
            this.jLabelScegliRete=new JLabel("Select second level network");
            this.jPanelSouthPanel=new JPanel(new FlowLayout());
            this.jPanelSouthPanel.add(this.jLabelScegliRete);
            this.jPanelSouthPanel.add(this.jComboBoxScegliRete);
            this.netPanel=new NetPanel(null ,"",null,CirclePanel.ROUTER);
            this.setLayout(new BorderLayout());
            this.add(this.netPanel,BorderLayout.CENTER);
            this.add(this.jPanelSouthPanel,BorderLayout.SOUTH);
            this.ComboActionPerformed(null);
        }
        if (level==ChoiceNetPanel.SHOW_LEVEL_3){
            this.jComboBoxScegliRete=new JComboBox();
            this.nomiNodi=net.getLevel_2_Name();
            String[] model=new String[this.nomiNodi.length];
            for(int i=0;i<this.nomiNodi.length;i++){
                model[i]="  "+this.nomiNodi[i]+"  ";
            }
            this.jComboBoxScegliRete.setModel(new javax.swing.DefaultComboBoxModel(model));
            this.jComboBoxScegliRete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ComboActionPerformed(evt);
                }
            });
            this.jLabelScegliRete=new JLabel("Select third level network");
            this.jPanelSouthPanel=new JPanel(new FlowLayout());
            this.jPanelSouthPanel.add(this.jLabelScegliRete);
            this.jPanelSouthPanel.add(this.jComboBoxScegliRete);
            this.netPanel=new NetPanel(null ,"",null,CirclePanel.ROUTER);
            this.setLayout(new BorderLayout());
            this.add(this.netPanel,BorderLayout.CENTER);
            this.add(this.jPanelSouthPanel,BorderLayout.SOUTH);
            this.ComboActionPerformed(null);
        }
    }
    
    
    private void ComboActionPerformed(java.awt.event.ActionEvent evt) {
        String rete =new String(this.nomiNodi[this.jComboBoxScegliRete.getSelectedIndex()]);
        this.remove(this.netPanel);
        //String numeroNodi=String.valueOf(this.nomiNodi.length);
        if(this.level==ChoiceNetPanel.SHOW_LEVEL_2){
            String titolo=new String("Network of second level "+rete);
            this.netPanel=new NetPanel(this.net.getLevel_2_MatrixOfNet(rete), titolo,this.net.getLevel_2_NameOfNet(rete),NetPanel.LEVEL2NET);
        }
        if(this.level==ChoiceNetPanel.SHOW_LEVEL_3){
            String titolo=new String("Network of third level number "+rete);
            this.netPanel=new NetPanel(this.net.getLevel_3_MatrixOfNet(rete), titolo, this.net.getLevel_3_NameOfNet(rete),NetPanel.ROUTER);
        }
        this.add(this.netPanel,BorderLayout.CENTER);
        this.validate();
    }
    
    
    public static void main(String[] arg){
        
    }
      
}
